package com.cdtye.itps.cms.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author jchen
 * @Date: 16:28 2021/3/24
 * @Description:
 * @Param
 * @return
**/
public class LineSlopeAndCurveUtil {



    /**
     *  封装导入结果类
     *
     * @param flag 保存标志,true:有数据保存到数据库
     * @param msg 错误信息
     * @return Map<String, Object>
     * @author hulj
     */
    public static Map<String, Object> handleImportResult(boolean flag, String msg) {
        Map<String, Object> result = new HashMap<>(4);
        if (!flag) {
            result.put("importStatus", ImportStatus.FAILURE.code);
            result.put("prompt",msg.concat("导入失败！没有导入数据！"));
            return result;
        }
        if (msg.length() == 0) {
            result.put("importStatus", ImportStatus.SUCCESS.code);
            result.put("prompt",msg.concat("导入成功"));
            return result;
        }
        result.put("importStatus", ImportStatus.HAS_PROBLEM.code);
        result.put("prompt",msg);
        return result;
    }

    /**
     * @Author jchen
     * @Date: 19:29 2021/3/24
     * @Description: 检测模板是否被更改
     * @Param [templateWorkBook, workBook]
     * @return boolean
    **/
    public static boolean CheckWorkBook(Sheet templateSheet,Sheet Sheet){
        Row templateRow = templateSheet.getRow(0);
        Row row = Sheet.getRow(0);
        if(templateRow.getLastCellNum()!=row.getLastCellNum()){
            return false;
        }
        for (int i = templateRow.getFirstCellNum(); i < templateRow.getLastCellNum(); i++) {
            Cell templateCell = templateRow.getCell(i, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
            Cell cell = row.getCell(i, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
            String templateCellValue = templateCell.getStringCellValue();
            String celLValue = cell.getStringCellValue();
            if(!StringUtils.equals(templateCellValue,celLValue)){
                return  false;
            }
        }
        return  true;
    }
}
